<!DOCTYPE html>
<html lang="zh-CN">

<head>
    <meta charset="UTF-8" />
    <title>17_深拷贝-简单深拷贝</title>
</head>

<body>
    <script>
        var obj = {
            a1name: 'zs',
            a2age: 18,
            a3gender: true,
            a4un: undefined,
            a5n: null,
            a6arr: ['1', '2', '3'],
            a7fun: function () {
                console.log(1111);
            },
            a8obj: {
                name: 'ls'
            },
            a9reg: /\w{6,8}/
        }

    // 不可以拷贝 数组、正则、null 会被拷贝为{}对象
        function deepCopy(target){
            var newObj = {}

            for(var x in target){
                newObj[x] = typeof target[x] === 'object' ? deepCopy(target[x]): target[x];
            }

            return newObj;
        }

        var result = deepCopy(obj);
        console.log(obj);
        console.log(result);
    </script>
</body>

</html>